#include <bits/stdc++.h>
#include "../../tools/tools.h"
using namespace std;

constexpr int INF = 0x7fffffff; // 无穷大
typedef long long ll;

class Solution {
public:
    int minimumArea(vector<vector<int>>& grid) {
        int n = grid.size(), m = grid[0].size(), ans = m * n;
        int rowS = 0, rowE = n - 1, colS = 0, colE = m - 1;
        for (int i = rowS; i <= rowE; i++) {
            int sum = 0;
            for (int j = colS; j <= colE; j++) {
                sum += grid[i][j];
            }
            if (sum == 0) rowS++;
            else break;
        }
        for (int i = rowE; i >= rowS; i--) {
            int sum = 0;
            for (int j = colS; j <= colE; j++) {
                sum += grid[i][j];
            }
            if (sum == 0) rowE--;
            else break;
        }
        for (int j = colS; j <= colE; j++) {
            int sum = 0;
            for (int i = rowS; i <= rowE; i++) {
                sum += grid[i][j];
            }
            if (sum == 0) colS++;
            else break;
        }
        for (int j = colE; j >= colS; j--) {
            int sum = 0;
            for (int i = rowS; i <= rowE; i++) {
                sum += grid[i][j];
            }
            if (sum == 0) colE--;
            else break;
        }
        return (rowE - rowS + 1) * (colE - colS + 1);
    }
};

int main(int argc, const char** argv) {
    // debug();
    return 0;
}
